package work20241225;

/**
 * @author zdl
 * @date 2024/12/25
 */
class SalTicket implements Runnable{
    int ticket = 100;
    @Override
    public void run() {
        while (true){
            synchronized (this){
                if (ticket > 0){
                    System.out.println(Thread.currentThread().getName()+"正在售卖第"+ticket+"票");
                    ticket--;
                }else {
                    System.out.println("没票了！");
                    break;
                }
            }
        }
    }

}
public class Demo1 {
    public static void main(String[] args) {
        SalTicket ticket = new SalTicket();
        new Thread(ticket,"猫眼").start();
        new Thread(ticket,"淘票票").start();
    }
}
